package com.campus.backend.service;

import com.campus.backend.entity.Delivery;
import com.campus.backend.entity.DeliveryApply;
import com.campus.backend.mapper.DeliveryApplyMapper;
import com.campus.backend.mapper.DeliveryMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 配送员申请表 服务实现类
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-05-21
 */
@Service
public class DeliveryApplyService extends ServiceImpl<DeliveryApplyMapper, DeliveryApply> {

    @Autowired
    private DeliveryMapper deliveryMapper;

    /**
     * 审核配送员申请事务方法
     * 同时更新申请状态和创建配送员记录
     * 
     * @param deliveryApply 配送员申请记录
     * @param delivery 配送员记录
     */
    @Transactional(rollbackFor = Exception.class)
    public void auditDeliveryApplyTransaction(DeliveryApply deliveryApply, Delivery delivery) {
        // 更新申请状态
        this.updateById(deliveryApply);
        // 创建配送员记录
        deliveryMapper.insert(delivery);
    }
}
